<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
	include("import.php");
	include("../service/categoryService.php");
	include("../service/dishService.php");
	include("../service/dayService.php");
?>
<title>Menu</title>
<script type="text/javascript">
	function getDetail(id){
		window.location.href = 'dishdetail.php?id=' + id;
	}
</script>
</head>
<body>
<div id="wrapper">
    <div id="wrapperContent">
    	<form id="searchForm" method="post" action="">
        <?php include("header.php");?>
        <div id="wrapperMainContent">
            <div id="menuContent">
                <div id="leftMenu">
                    <div class="smallContent">
                        <div class="menu-header-bg"></div>
                        <div class="menu-body-bg">
                        	<div id="text-menu"></div>
                            <div id="text-inst">
                            	Các bạn hãy khám phá dịch vụ của chúng tôi<br/>
                                (Ngon - Rẻ - Phục vụ tận nơi)<br/>
                                &ldquo; Đặt cơm trước 11h trưa &rdquo;
                            </div>
                        </div>
                        <div class="menu-footer-bg"></div>
                    </div>
                    <div class="largeContent">
						<div class="menu-header-bg"></div>
                        <div class="menu-body-bg">
                        	<div class="category">
                            	<?php
									$keyword = "";
									if($_POST['keyword'] != '') $keyword = $_POST['keyword'];
								
									$cateResult = getCategoryByOrder(1, $keyword);
									
									$cateContent = ConnectionManager::getInstance()->fetchArray();
									$firstCateId = $cateContent['CAT_ID'];
									if($firstCateId != "") echo "<span>1. ".$cateContent['CAT_NAME']."</span>";
                                ?>
                            </div>
                            <div class="categoryContent">
                            	<?php
                                	if($firstCateId != ''){
										$days = getAllDays();
										$numRow = ConnectionManager::getInstance()->getNumRows();
										$count = 0;
										$sunday = "";
									
										while($day = current($days)) {
											$count++;
											if($count != 1){
												$dishResult = getDishByCateAndDay($firstCateId, key($days), $keyword);
												if(mysql_num_rows($dishResult) > 0)
													echo "<div class=\"title\">".$day."</div>";
												
												$countDish = 0;
												while($dishRow = mysql_fetch_array($dishResult)){
													$countDish++;
													echo "<div class=\"contentRow\" onclick=\"getDetail(".$dishRow['DISH_ID'].");\">
															<div class=\"dish\">$countDish. ".$dishRow["DISH_NAME"]."</div>".
														   "<div class=\"price\">giá: ".number_format($dishRow["DISH_PRICE"]."000", 0, ",", ".")."đ</div>
														 </div>";
												}
											}
											else $sunday = $day;	
											next($days);
										}
									}
								?>
                            </div>
                            <?php
								if($firstCateId != ''){
									$sundayResult = getDishByCateAndDay($firstCateId, 0, $keyword);
									if(ConnectionManager::getInstance()->getNumRows() > 0){
							?>
                            <div class="spacer">&nbsp;</div>
                            <div class="categoryContent">
	                            <div id="dish-sun"><?php echo "Đặc biệt ".$sunday; ?></div>
                                <?php
									
										$countDishOnSuncday = 0;
										if($sundayRow = ConnectionManager::getInstance()->getNumRows() > 0){
											while($sundayRow = ConnectionManager::getInstance()->fetchArray()){
												$countDishOnSuncday++;
												echo "<div class=\"contentRow\" onclick=\"getDetail(".$sundayRow['DISH_ID'].");\">
															<div class=\"dish\">$countDishOnSuncday. ".$sundayRow["DISH_NAME"]."</div>".
															"<div class=\"price\">giá: ".number_format($sundayRow["DISH_PRICE"]."000", 0, ",", ".")."đ</div>
													 </div>";
											}
										}
								?>
                            	</div>
                            <?php 
									}
								}
								//if($firstCateId == '') echo "<div id=\"noResult\">Không có kết quả</div>";
							?>
                        </div>
                        <div class="menu-footer-bg"></div>
                    </div>
                </div>
                <div id="rightMenu">
                	<div class="largeContent">
						<div class="menu-header-bg"></div>
                        <div class="menu-body-bg">
                        	<?php
								$searchingDishResult = getCategoryByDish($keyword);
								$numCate = ConnectionManager::getInstance()->getNumRows(); 
								//if($numCate == 0 && isset($_POST['keyword'])) echo "<div id=\"noResult\">Không có kết quả</div>";
								$count = 1;
								
								while($row = mysql_fetch_array($searchingDishResult)){
									$count++;
									echo "<div class=\"category\"><span>$count. ".$row['CAT_NAME'].
										 "</span></div><div class=\"categoryContent\">";
									
									$dishResult = getDishByCategory($row['CAT_ID']);
									$countDish = 0;
									
									while($dishRow = mysql_fetch_array($dishResult)){
										$countDish++;
										echo "<div class=\"contentRow\" onclick=\"getDetail(".$dishRow['DISH_ID'].");\">
													<div class=\"dish\">$countDish. ".$dishRow['DISH_NAME']."</div>
										           <div class=\"price\">giá: ".number_format($dishRow['DISH_PRICE']."000", 0, ",", ".")."đ</div>
											  </div>";
									}
									echo "</div>";
								}
							?>
                        </div>
                        <div class="menu-footer-bg"></div>
                    </div>
                    <div id="push" style="clear: both;"></div>
                	<div class="smallContent">
                        <div class="menu-header-bg"></div>
                        <div class="menu-body-bg">
                        	<div id="hotline-bye">hotline:</div>
                            <div id="hotline-phone">&nbsp;(08)6680 6883 - 0904944660</div>
                            <div id="bye">Kính chúc quý khách luôn vui vẻ, hạnh phúc và luôn luôn thành công trong mọi lãnh vực của cuộc sống</div>
                        </div>
                        <div class="menu-footer-bg"></div>
                    </div>
                </div>
            </div>
        </div>
        </form>
    </div>
</div>
<div id="exp"></div>
<?php include("footer.php");?>
<script type="text/javascript">
	$('#exp').height($(document).height() - $('#wrapper').height() + 30);
    $('#push').height($('#menuContent').height() - $('#rightMenu').height());
</script>
<?php ConnectionManager::getInstance()->closeConnection();?>
</body>
</html>